package zero.tech.games.pdk.event;

import com.alibaba.fastjson.JSONObject;

import zero.tech.core.event.EventListener;
import zero.tech.core.event.EventType;
import zero.tech.games.logic.common.Room;
import zero.tech.games.logic.data.LogicEventType;
import zero.tech.games.pdk.data.PdkConfig;
import zero.tech.games.pdk.data.PdkGameBase;
import zero.tech.games.pdk.data.PdkRoomCache;
import zero.tech.games.pdk.data.PdkTimer;

public class RoomCreated implements EventListener{

	@Override
	public EventType netEventType() {
		return LogicEventType.ROOM_CREATED;
	}

	@Override
	public void notifyEvent(Object... objs) {
		Room room = (Room) objs[0];
		PdkTimer pdkTimer=new PdkTimer(room.getRoom_id());
		room.setTimer(pdkTimer);
		PdkRoomCache pdkRoomCache=new PdkRoomCache(room.getRoom_id());
		room.setRoomCache(pdkRoomCache);
		PdkConfig pdkConfig=JSONObject.parseObject(room.getConfigStr(),PdkConfig.class);
		room.setGameConfig(pdkConfig);
		PdkGameBase pdkGameBase=new PdkGameBase(room.getRoom_id());
		room.setGameBase(pdkGameBase);
	}

	@Override
	public boolean asynchronous() {
		return false;
	}

}
